function dlmcellwrite(filename,cell_array)
% Stripped down version of dlmcell that writes numeric cell array

% dcmcell:  Roland Pfister (roland_pfister@t-online.de)


if ~isnumeric(cell_array{1,1})
    disp('Error - Contents of cell_array not of the type numeric'); 
    return;
end

%% Open output file and prepare output array.
output_file = fopen(filename,'w');
output = cell(size(cell_array,1),size(cell_array,2));

%% Evaluate and write input array.
for i = 1:size(cell_array,1)
for j = 1:size(cell_array,2)
    if numel(cell_array{i,j}) == 0
        output{i,j} = '   ';
    else
        output{i,j} = num2str(cell_array{i,j}','%d , ');
    
    end;
     
     % Cell i,j is written to the output file. A delimiter is appended
     % for all but the last element of each row.
     fprintf(output_file,'%s \n',output{i,j}(1:end-2));

end;
% At the end of a row, a newline is written to the output file.
fprintf(output_file,'\n');
end;

%% Close output file.    
fclose(output_file);
